package com.gdth.bank.model;

import java.util.List;

import com.gdth.bank.BankApplication;
import com.gdth.bank.service.CjkhjlService;
import com.gdth.database.bean.DaoSession;
import com.gdth.database.bean.NotificationT;
import com.gdth.database.bean.NotificationTDao;
import com.gdth.database.bean.TAppBfrjJbxxb;
import com.gdth.http.method.HttpMethodServlet;
import com.gdth.utils.GsonUtil;
import com.google.gson.Gson;

import org.greenrobot.greendao.query.QueryBuilder;

import rx.Observable;

public class SynchronizeModel {
	/**
	 * 上传采集客户记录
	 * @param wybs
	 * @return
	 */
	public Observable<String> upLoadCjkhxx(String str){
		return HttpMethodServlet.getInstance().upLoadCjkhxx(str);
	}
	//判断网络
	public Observable<String> getWl(String content){
		return HttpMethodServlet.getInstance().getWl(content);
	}
	
	/**
	 * 上传采集客户记录后修改状态
	 * @param arg0
	 */
	public void UpdateZtForBfrj(String arg0){
		CjkhjlService mCjkhjlService = new CjkhjlService();
		mCjkhjlService.updateBfrjZt(arg0);
	}
	
	/**
	 * 根据状态获取需要更新的采集客户数据
	 * @return
	 */	
	public String getAllCjkhxxByZt(){
		CjkhjlService mCjkhjlService = new CjkhjlService();
		List<TAppBfrjJbxxb> mList = mCjkhjlService.getAllBfrjByZt();
		if (mList == null || mList.size() == 0){
			return null;
		}
		
		Gson mGson = GsonUtil.getGson();
		
		String str = mGson.toJson(mList);
		
		return str;
	}
	
	public void saveAllBfrj(List<TAppBfrjJbxxb> mList) {
		CjkhjlService mCjkhjlService = new CjkhjlService();
		mCjkhjlService.saveAllBfrj(mList);
	}
	
	public void  changeListStatus() {
		CjkhjlService mCjkhjlService = new CjkhjlService();
		mCjkhjlService.getTAppBfrjBfjlStatus();
	}
	
	/**
	 * 将通知保存在本地啊
	 * @param mList
	 */
	public void saveNotifitionList(List<NotificationT> mList) {
		DaoSession session = BankApplication.getDaoSession();
		NotificationTDao dao = session.getNotificationTDao();
	
		for (NotificationT obj : mList) {
			QueryBuilder<NotificationT> query = dao.queryBuilder();
			int xxtsid = obj.getXxtsId();
			query.where(NotificationTDao.Properties.XxtsId.eq(xxtsid));
			List<NotificationT> mLists = query.list();
			if(mLists.size() > 0) {
				obj.setId(mLists.get(0).getId());
			}else {
				obj.setId(null);
			}
			
			dao.insertOrReplace(obj);
		}
	}
	
	
		
	/**
	 * 上传电子产品pos的信息
	 * @param str
	 * @return
	 */
	public Observable<String> upLoadDzcpPos(String str){
		return HttpMethodServlet.getInstance().upLoadDzcpPos(str);
	}
	
	/**
	 * 上传电子产品etc的信息
	 * @param str
	 * @return
	 */
	public Observable<String> upLoadDzcpEtc(String str){
		return HttpMethodServlet.getInstance().upLoadDzcpPos(str);
	}
	
	public Observable<String> getYhForUpdate(String content) {
		return HttpMethodServlet.getInstance().getYhForUpdate(content);
	}
	
	public Observable<String> getAllBfrj(String content) {
		return HttpMethodServlet.getInstance().getAllCjkhxx(content);
	}
	public Observable<String> gethddj(String content) {
		return HttpMethodServlet.getInstance().gethddj(content);
	}
	public Observable<String> getBmList(String content) {
		return HttpMethodServlet.getInstance().getBmList(content);
	}
	public Observable<String> saveqbList(String content) {
		return HttpMethodServlet.getInstance().saveqbList(content);
	}
	public Observable<String> savegxqbList(String content) {
		return HttpMethodServlet.getInstance().savegxqbList(content);
	}
	public Observable<String> getDbjjdjList(String content) {
		return HttpMethodServlet.getInstance().getDbjjdjList(content);
	}
	public Observable<String> getDbjjdjJson(String content) {
		return HttpMethodServlet.getInstance().getDbjjdjJson(content);
	}
	public Observable<String> getbjjdjList(String content) {
		return HttpMethodServlet.getInstance().getbjjdjList(content);
	}
	public Observable<String> getbjjdjUpList(String content) {
		return HttpMethodServlet.getInstance().getbjjdjUpList(content);
	}
	public Observable<String> getbjjdjOffList(String content) {
		return HttpMethodServlet.getInstance().getbjjdjOffList(content);
	}
	public Observable<String> getDbjjdjUpList(String content) {
		return HttpMethodServlet.getInstance().getDbjjdjUpList(content);
	}
	public Observable<String> getDbjjdjOffList(String content) {
		return HttpMethodServlet.getInstance().getDbjjdjOffList(content);
	}
	public Observable<String> getGwList(String content) {
		return HttpMethodServlet.getInstance().getGwList(content);
	}
	public Observable<String> getdjJson(String content) {
		return HttpMethodServlet.getInstance().getdjJson(content);
	}
	public Observable<String> deletejson(String content) {
		return HttpMethodServlet.getInstance().deletejson(content);
	}
	public Observable<String> NotificationList(String content) {
		return HttpMethodServlet.getInstance().notificationList(content);
	}
}
